//
//  E7MenuScene.cpp
//  E7_ENGINE
//
//  Created by cc on 12-2-29.
//  Copyright (c) 2012年 PalmGame. All rights reserved.
//

#include "E7MenuScene.h"

#include "E7GameManager.h"

CE7MenuScene::CE7MenuScene()
{
//    m_pBackSprite = NULL ;
    m_pMenuLayer = NULL ;
    m_bRunAnimation = false ;
}

CE7MenuScene::~CE7MenuScene()
{
    Stop() ;
}

// 循环.
void CE7MenuScene::step(float dt)
{
    m_fTotalTime += dt ;

    if (!m_pMenuLayer->Loop())
    {
        Stop() ;
        return ;
    }
}

void CE7MenuScene::Start()
{
//    printf("enter menu scene - s\n") ;

    if (S_START == m_eStep)
    {
        return ;
    }
    
    m_eStep = S_START ;
    m_fTotalTime = ZERO_FLOAT ;
    m_bIsVisible = true ;

//    m_pBackSprite = new CE7Sprite() ;
//    m_pBackSprite->Init("back_menu1.png") ;
//    addChild(m_pBackSprite) ;

    if (m_bRunAnimation)
    {
        m_pMenuLayer = new CE7MenuLayer() ;
    }
    else
    {
        m_pMenuLayer = new CE7MenuLayer(0) ;
    }
    addChild(m_pMenuLayer) ;

//    m_pBackSprite1 = new CE7Sprite() ;
//    m_pBackSprite1->Init("back_menu2.png") ;
//    addChild(m_pBackSprite1) ;

    schedule(schedule_selector(CE7MenuScene::step)) ;

//    printf("enter menu scene - e\n") ;
}

void CE7MenuScene::Stop()
{
    if (S_START != m_eStep)
    {
        return ;
    }

    m_eStep = S_STOP ;

    unscheduleAllSelectors() ;
//    removeAllChildrenWithCleanup(false) ; // cleanup flag.

//    SAFE_RELEASE(m_pBackSprite) ;
//    SAFE_RELEASE(m_pMenuLayer) ;

    m_fTotalTime = INVALID_FLOAT ;
    m_bIsVisible = false ;

    g_pGameManager->ChangeSceneState(SS_GAME) ;
//    printf("change to single game scene\n") ;
}

